package com.ef.service.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.ef.dao.LeadsEventHistoryDao;
import com.ef.domain.Leads;
import com.ef.domain.LeadsEventHistory;
import com.ef.service.LeadsEventHistoryService;
import com.ef.util.CustomExample;
import com.ef.util.PaginationSupport;

public class LeadsEventHistoryServiceImpl extends BaseServiceImpl implements
		LeadsEventHistoryService {

	private LeadsEventHistoryDao leadsEventHistoryDao;

	public List<LeadsEventHistory> findByLeads(Leads leads) {

		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(LeadsEventHistory.class);
		detachedCriteria.add(Restrictions.eq("leads", leads));
		detachedCriteria.addOrder(Order.desc("dealTime"));
		return leadsEventHistoryDao.findAllByCriteria(detachedCriteria);
	}

	public PaginationSupport<LeadsEventHistory> findByExample(
			CustomExample<LeadsEventHistory> example, int startIndex,
			int pageSize) {
		return leadsEventHistoryDao.findPageByExample(example, startIndex,
				pageSize);
	}

	public void saveOrUpdate(LeadsEventHistory entity) {
		leadsEventHistoryDao.save(entity);
	}

	public LeadsEventHistoryDao getLeadsEventHistoryDao() {
		return leadsEventHistoryDao;
	}

	public void setLeadsEventHistoryDao(
			LeadsEventHistoryDao leadsEventHistoryDao) {
		this.leadsEventHistoryDao = leadsEventHistoryDao;
	}

	public LeadsEventHistory findById(Long id) {
		return leadsEventHistoryDao.findById(id);
	}
}
